/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			cst_tlb.h
  \date			June 2011
  \author		TNick

  \brief		Contains the definition for CstTlb class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n
 Please read ReadMe.txt and Licence.txt in root folder @n
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __CST_TLB_INC__
#define __CST_TLB_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

class	CstTlb;
class	CstAct;

#include	<QRect>
#include	<QHash>
#include	<QWidget>
#include	<generic/cc_l2d.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */


struct		CstTlbPrp	{

	enum		CSTTLBFLAGS		{
		NONE		= 0x00000000,
		FLOATING	= 0x00000001,
		SHOWN		= 0x00000002,

		FLGMAX
	};

	/// tell if it's floating or docked
	CSTTLBFLAGS		flags;

	/// position and size when flying
	QRect			geom;

	/// associated widget
	QWidget*		panel_w;

	/// the name of this toolbar
	QString			s_name;

	/// list of actions; NULL signals a separator
	QList<CstAct*>	l_actions;

};



/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class representing a single customisable action
/**
*/
class CstTlb : public CC_L2D		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:
	/// properties of this toolbar
	CstTlbPrp				data;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:

	/// constructor;
	CstTlb		(void) : CC_L2D() {
		data.flags = CstTlbPrp::FLOATING;
		data.geom = QRect(0,0,0,0);
		data.panel_w = NULL;
		data.s_name = QObject::tr("new toolbar");
	}

	CstTlb		(QString s_name, bool b_floating = true) : CC_L2D() {
		data.flags = (b_floating ? CstTlbPrp::FLOATING : CstTlbPrp::NONE);
		data.geom = QRect(0,0,0,0);
		data.panel_w = NULL;
		data.s_name = s_name;
	}

	/// destructor;
	virtual				~CstTlb		(void) {}


	/// set the name
	inline  void setName(QString s_new) {
		data.s_name = s_new;
	}
	/// get name
	inline QString name(void) const {
		return data.s_name;
	}

	/// tell if toolbar is floating or not
	inline bool isFloating(void) const { return ((data.flags & CstTlbPrp::FLOATING) != 0); }
	/// set floating state
	inline void floating(bool b_new) {
		if (b_new)
			data.flags = static_cast<CstTlbPrp::CSTTLBFLAGS>(data.flags | CstTlbPrp::FLOATING);
		else
			data.flags = static_cast<CstTlbPrp::CSTTLBFLAGS>(data.flags & ~CstTlbPrp::FLOATING);
	}

	/// tell if toolbar is visible or not
	inline bool isVisible(void) const {
		return ((data.flags & CstTlbPrp::SHOWN) != 0); }
	/// set visible state
	inline void visible(bool b_new) {
		if (b_new)
			data.flags = static_cast<CstTlbPrp::CSTTLBFLAGS>(
						data.flags | CstTlbPrp::SHOWN);
		else
			data.flags = static_cast<CstTlbPrp::CSTTLBFLAGS>(
						data.flags & ~CstTlbPrp::SHOWN);
	}



	/// tell the position of the toolbar when flying
	inline QRect position(void) const { return data.geom; }
	/// set the position of the toolbar when flying
	inline void setPosition (QRect r_new) { data.geom = r_new; }

	/// get associated widget
	inline QWidget* panel(void) const { return data.panel_w; }
	/// set associated widget
	inline void setPanel(QWidget* w_new) { data.panel_w = w_new; }


	/// copy the properties from another item
	inline void setProperties(const CstTlb* p_source)
	{ data = p_source->data; }
	/// set the properties from a data structure
	inline void setProperties(const CstTlbPrp* p_source)
	{ data = *p_source; }
	/// set the properties from a data structure but replace actions
	inline void setProperties(const CstTlbPrp* p_source,
							  QHash<CstAct*, CstAct*> transl)
	{
		data = *p_source;
		for (int i = 0; i < data.l_actions.count(); i++)
			{
				CstAct*	p_csta = data.l_actions.at(i);
				CstAct*	p_csta_1 = transl.value(p_csta);
				data.l_actions[i] = p_csta_1;
			}
	}
	/// copy properties from another one
	inline void setProperties(const CstTlb* p_source,
							  QHash<CstAct*, CstAct*> transl)
	{
		setProperties(&p_source->data,transl);
	}


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class CstTlb	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __CST_TLB_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */

